#ifndef CONFIG_H
#define CONFIG_H

#include <defs/export.h>
#include <defs/global.h>
#include <Core/entity.h>

#include <QtCore>

namespace Opl { namespace Core {
    class IConfig;
}}

namespace Optra
{
    O_PRIVATE_DECLARE(ConfigManager);
    class ConfigManager : public QObject
    {
        Q_OBJECT
    public:
        ConfigManager(QObject *parent = 0);
        ~ConfigManager();

        void registerConfig(Opl::Core::Entity::EntityId id, const QString& path, bool createIfNotExists);
        Opl::Core::IConfig* configFor(Opl::Core::Entity::EntityId id);

        QVariant value(Opl::Core::Entity::EntityId id, const QString& section, const QString& key, const QVariant& def = QVariant());
        bool setValue(Opl::Core::Entity::EntityId id, const QString& section, const QString& key, const QVariant& val);
        static ConfigManager* instance();

    signals:

    private:
        O_PRIVATE_DECLARE_MEMBER(ConfigManager);
    };


    inline QVariant conf(Opl::Core::Entity::EntityId id, const QString& section, const QString& key, const QVariant& def = QVariant()){
        return ConfigManager::instance()->value(id, section, key, def);
    }

    inline QVariant conf(const Opl::Core::Entity& ent, const QString& section, const QString& key, const QVariant& def = QVariant()){
        return conf(ent.unique(), section, key, def);
    }
}



#endif // CONFIG_H


